package com.example.lenovo.myapplication;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        ImageView button1=(ImageView) findViewById(R.id.button1);
        button1.setOnClickListener(this);
        replaceFragment(new WeChartFragment());

        ImageView button2=(ImageView) findViewById(R.id.button2);
        button2.setOnClickListener(this);
        replaceFragment(new WeChartFragment());

        ImageView button3=(ImageView) findViewById(R.id.button3);
        button3.setOnClickListener(this);
        replaceFragment(new WeChartFragment());

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button1:
                replaceFragment(new WeChartFragment());
                break;
            case R.id.button2:
                replaceFragment(new ChartFragment());
                break;
            case R.id.button3:
                replaceFragment(new PersonalFragment());
                break;
            default:
                break;
        }
    }

    private void replaceFragment(Fragment fragment) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.exchange,fragment);
        transaction.commit();
    }


}
